<template>
  <div>
    <!-- navbar导航栏 -->
    <van-nav-bar
      left-text="返回"
      title="阅读历史"
      left-arrow
      @click-left="$router.back()"
    />
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in list" :key="item.art_id" :title="item.title" />
    </van-list>
  </div>
</template>

<script>
import { getSearchHistory } from '@/api/user'
export default {
  name: 'HistoryIndex',
  data () {
    return {
      page: {
        page: 1,
        per_page: 10
      },
      list: [],
      loading: false,
      finished: false
    }
  },
  methods: {
    async onLoad () {
      const res = await getSearchHistory(this.page)
      this.list = [...this.list, ...res.data.results]
      this.loading = false
      if (res.data.results.length !== 10) {
        this.finished = true
      } else {
        this.page.page += 1
      }
    }
  }
}
</script>

<style></style>
